package cn.lkk.samples.lang.inheritance.enums;

import java.util.Scanner;

/**
 * 演示枚举类型
 */
public class EnumTest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a size:");
        String input = in.next().toUpperCase();

        //根据字符串创建一个枚举类型
        Size size = Enum.valueOf(Size.class, input);
        //调用Enum.toString()
        System.out.println("size=" + size);
        //获得枚举变量的位置
        System.out.println("ordinal=" + size.ordinal());
        //调用枚举变量的方法
        System.out.println("abbreviation=" + size.getAbbreviation());
        //比较枚举类型
        if (size == Size.EXTRA_LARGE)
            System.out.println("Good job--you paid attention to _.");
    }

}

//枚举类型实际上就是一个类，该类继承自 Enum 基类，并且只有固定的几个对象
enum Size {
    SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");

    private String abbreviation;

    public String getAbbreviation() {
        return abbreviation;
    }

    Size(String abbreviation) {
        this.abbreviation = abbreviation;
    }
}

//class SizeClass extends Enum{
//
//    static final SizeClass SMALL=new SizeClass("S");
//
//    //=========================枚举的成员========================
//    private String abbreviation;
//
//    public String getAbbreviation() {
//        return abbreviation;
//    }
//
//    SizeClass(String abbreviation) {
//        this.abbreviation = abbreviation;
//    }
//}
